package com.ymatou.iapi.userservice.parameter.enums;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

/**
 * Created by Administrator on 2017-1-2.
 */
public enum UserLogoTypeEnum  {
    Original(0,"Original"),
    Small(1,"Small"),
    Middle(2,"Middle")
    ;
    private int code;
    private String message;
    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    UserLogoTypeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 通过代码获取枚举项
     *
     * @param code
     * @return
     */
    public static UserLogoTypeEnum getByCode(Integer code) {
        for (UserLogoTypeEnum enumItem : UserLogoTypeEnum.values()) {
            if (enumItem.getCode() == code) {
                return enumItem;
            }
        }
        return null;
    }

    /**
     *通过枚举值获取枚举项
     * @param msg
     * @return
     */
    public static UserLogoTypeEnum getByMessage(String msg) {
        for (UserLogoTypeEnum enumItem : UserLogoTypeEnum.values()) {
            if (enumItem.getMessage().equalsIgnoreCase(msg)) {
                return enumItem;
            }
        }
        return null;
    }

    /**
     * 使用@JSONCreator来指定构造函数来创建枚举对象
     * @param val
     * @return
     */
    public static UserLogoTypeEnum getValue(String val){
        if(StringUtils.isNumeric(val)){
            return getByCode(NumberUtils.toInt(val));
        }else{
            return getByMessage(val);
        }
    }
}
